package org.example;

import java.util.HashMap;
import java.util.Map;
import org.example.sdk.AuthResult;
import org.example.sdk.JitConstant;
import org.example.sdk.JitGatewayUtil;
import org.example.sdk.JitGatewayUtilBean;
import org.example.sdk.JitResult;

public class InspurJitUkeyService implements UKeyService {

	private Map config = new HashMap<String, Object>();

	InspurJitUkeyService(Map<String, String> config) {
		this.config = config;
	}

	@Override
	public JitResult randomOrignal() throws Exception {
		JitGatewayUtil.initConfig(config);
		return JitGatewayUtil.random();
	}

	@Override
	public AuthResult authGateway(JitGatewayUtilBean bean) throws Exception {
		JitGatewayUtil.initConfig(config);
		Map  configMap = JitGatewayUtil.getConfigMap();
		bean.setAuthURL(configMap.get(JitConstant.ConfigConstant.KEY_AUTH_URL).toString());
		Object generateQRCodeURL = configMap.get(JitConstant.ConfigConstant.KEY_GENERATEQRCODE_URL);
		bean.setGenerateQRCodeURL(generateQRCodeURL == null ? null: generateQRCodeURL.toString());
		Object queryQRCodeStateURL = configMap.get(JitConstant.ConfigConstant.KEY_QUERYQRCODESTATE_URL);
		bean.setQueryQRCodeStateURL(queryQRCodeStateURL == null ? null : queryQRCodeStateURL.toString());
		return JitGatewayUtil.auth(bean);
	}
}
